package itcz.example.pattern.behavior_type.observer;

import java.util.ArrayList;
import java.util.List;

/**
 * @ClassName: SubscriptionSubject
 * @Author: ITCZ
 * @Date: 2025-07-29
 * @Description: 观察者模式 - 具体主题（具体被观察者） 订阅公众号类
 */
public class SubscriptionSubject implements Subject {

    //储存订阅公众号的微信用户
    private List<Observer> weixinUserlist = new ArrayList<>();

    @Override
    public void attach(Observer observer) {
        weixinUserlist.add(observer);
    }

    @Override
    public void detach(Observer observer) {
        weixinUserlist.remove(observer);
    }

    @Override
    public void notify(String message) {
        for (Observer observer : weixinUserlist) {
            observer.update(message);
        }
    }
}
